package RozetkaPages;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

/**
 * Created by Yulia on 06.04.14.
 */
public class OrderPage extends BasePage{

    private static final String PAGE_URL = "";

    private By applicationTitle = By.cssSelector(".check-title");
    private By reciever = By.cssSelector("#reciever_name");
    private By recieverPhone = By.cssSelector("#reciever_phone");
    private By recieverEmail = By.cssSelector("#reciever_email");
    private By city = By.cssSelector("#suggest_locality");
    private By continueButton = By.xpath("//button[@class='btn-link-i'][@tabindex='6']");
    private By orderButton = By.cssSelector("#make-order");
    private By citySelect = By.xpath("//ul[@class='suggestions']/li[1]");

    public OrderPage(WebDriver driver)
    {
        super(driver,PAGE_URL);
    }

    public void open()
    {
        driver.get(pageUrl);
    }

    @Override
    public boolean isOpened()
    {
        return driver.findElement(applicationTitle).isDisplayed();
    }

    public void fillOrderForm(String userName, String userCity, String userNumber,String userEmail)
    {
        driver.findElement(reciever).clear();
        driver.findElement(reciever).sendKeys(userName);

        driver.findElement(city).clear();
        driver.findElement(city).sendKeys(userCity);
        driver.findElement(citySelect).click();

        driver.findElement(recieverPhone).clear();
        driver.findElement(recieverPhone).sendKeys(userNumber);

        driver.findElement(recieverEmail).clear();
        driver.findElement(recieverEmail).sendKeys(userEmail);

        driver.findElement(continueButton).click();

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.findElement(orderButton).isEnabled();
    }
}
